package cn.itcast.bos.web.action.system;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;

import cn.itcast.bos.domain.system.Role;
import cn.itcast.bos.service.system.RoleService;
import cn.itcast.bos.web.action.common.BaseAction;
@SuppressWarnings("all")
@Namespace("/")
@ParentPackage("json-default")
@Controller
@Scope("prototype")
public class RoleAction extends BaseAction<Role>{
	@Autowired
	private RoleService roleService;
	
     @Action(value="role_list",results={@Result(name="success",type="json")})
     public String list(){
         System.out.println("查询所有的角色");    	 
    	 List<Role> list = roleService.findAll();
    	 ActionContext.getContext().getValueStack().push(list);
    	 return SUCCESS;
     }
     
     //属性驱动  前台表单项的id都是json对象中遍历出来的 json对象遍历出来的都是String字符串
     private String [] permissionIds;//权限id
     private String menuIds;//菜单id
     
     

	public String getMenuIds() {
		return menuIds;
	}

	public void setMenuIds(String menuIds) {
		this.menuIds = menuIds;
	}

	public String[] getPermissionIds() {
		return permissionIds;
	}

	public void setPermissionIds(String[] permissionIds) {
		this.permissionIds = permissionIds;
	}

 

	//保存角色
	@Action(value="role_save",results={@Result(name="success",type="redirect",location="pages/system/role.html")})
     public String save(){
		System.out.println("保存角色"+permissionIds);
		roleService.save(model,permissionIds,menuIds);
    	 return SUCCESS;
     }
}
